#include "DIALOG.h"
#include "MC_include.h"

#define ID_FRAMEWIN_2     (GUI_ID_USER + 0x60)
#define ID_JBUTTON_0     (GUI_ID_USER + 0x63) //X +
#define ID_JBUTTON_1     (GUI_ID_USER + 0x64) //X -
#define ID_JBUTTON_2     (GUI_ID_USER + 0x65) //Y +
#define ID_JBUTTON_3     (GUI_ID_USER + 0x66) //Y-
#define ID_JBUTTON_5     (GUI_ID_USER + 0x68) //Z+
#define ID_JBUTTON_6     (GUI_ID_USER + 0x69) //Z-
#define ID_JTEXT_0     (GUI_ID_USER + 0x6B)
#define ID_JTEXT_1     (GUI_ID_USER + 0x6C)
#define ID_JTEXT_2     (GUI_ID_USER + 0x6D)
#define ID_JTEXT_3     (GUI_ID_USER + 0x6E)
#define ID_JTEXT_4     (GUI_ID_USER + 0x6F)
#define ID_JTEXT_5     (GUI_ID_USER + 0x71)
#define ID_JTEXT_6     (GUI_ID_USER + 0x72)
#define ID_JTEXT_7     (GUI_ID_USER + 0x73)
#define ID_JTEXT_8     (GUI_ID_USER + 0x74)
#define ID_JTEXT_9     (GUI_ID_USER + 0x75)
#define ID_JTEXT_10     (GUI_ID_USER + 0x76)
#define ID_JTEXT_11     (GUI_ID_USER + 0x77)
#define ID_JTEXT_12     (GUI_ID_USER + 0x78)
#define ID_JTEXT_13     (GUI_ID_USER + 0x79)
#define ID_JTEXT_14     (GUI_ID_USER + 0x7A)

#define ID_JBUTTON_7     (GUI_ID_USER + 0x7B)
#define ID_JBUTTON_8     (GUI_ID_USER + 0x7C)
#define ID_JBUTTON_9     (GUI_ID_USER + 0x7D)
#define ID_JBUTTON_10     (GUI_ID_USER + 0x7E)
#define ID_JBUTTON_11     (GUI_ID_USER + 0x7F)
#define ID_JBUTTON_12     (GUI_ID_USER + 0x80)
#define ID_JBUTTON_13     (GUI_ID_USER + 0x81)
#define ID_JBUTTON_14     (GUI_ID_USER + 0x82)

static const GUI_WIDGET_CREATE_INFO _aDialogHandlewinCreate[] =
{
    { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_2, 0, 0, 800, 480, 0, 0x64, 0 },
    { BUTTON_CreateIndirect, "X+", ID_JBUTTON_0, 548, 335, 65, 65, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "X-", ID_JBUTTON_1, 385, 335, 65, 65, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Y+", ID_JBUTTON_2, 470, 243, 65, 65, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Y-", ID_JBUTTON_3, 470, 336, 65, 65, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Z+", ID_JBUTTON_5, 630, 243, 65, 65, 0, 0x0, 0},
    { BUTTON_CreateIndirect, "Z-", ID_JBUTTON_6,  630, 334, 65, 65, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Text", ID_JTEXT_0, 424, 11, 200, 32, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "speed_Text", ID_JTEXT_1, 648, 3, 131, 52, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "position_text", ID_JTEXT_2, 1, 5, 170, 39, 0, 0x64, 0 },
    //{ TEXT_CreateIndirect, "Text", ID_JTEXT_3, 32, 112, 80, 20, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "X_text", ID_JTEXT_3, 20, 60, 50, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "Y_Text", ID_JTEXT_4, 20, 110, 50, 50, 0, 0x64, 0},
    { TEXT_CreateIndirect, "Z_Text", ID_JTEXT_5, 20, 160, 50, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "XPText", ID_JTEXT_6, 70, 60, 200, 55, 0, 0x64, 0  },
    { TEXT_CreateIndirect, "YPText", ID_JTEXT_7,  70, 110, 200, 43, 0, 0x64, 0},
    { TEXT_CreateIndirect, "ZPText", ID_JTEXT_8, 70, 160, 200, 50, 0, 0x64, 0  },
    { TEXT_CreateIndirect, "XWText", ID_JTEXT_9, 20, 240, 50, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "YWText", ID_JTEXT_10, 20, 290, 50, 50, 0, 0x64, 0},
    { TEXT_CreateIndirect, "ZWText", ID_JTEXT_11, 20, 340, 50, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "XWPText", ID_JTEXT_12, 70, 240, 200, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "YWPText", ID_JTEXT_13, 70, 290, 168, 50, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "ZWPText", ID_JTEXT_14, 70, 340, 200, 50, 0, 0x64, 0 },

    { BUTTON_CreateIndirect, "x0", ID_JBUTTON_7, 200+300, 60, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x1", ID_JBUTTON_8, 200+350, 60, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x2", ID_JBUTTON_9, 200+400, 60, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x3", ID_JBUTTON_10, 200+450, 60, 42, 42, 0, 0x0, 0},
    { BUTTON_CreateIndirect, "x4", ID_JBUTTON_11, 200+300, 110, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x5", ID_JBUTTON_12, 200+350, 110, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x6", ID_JBUTTON_13, 200+400, 110, 42, 42, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "x7", ID_JBUTTON_14, 200+450, 110, 42, 42, 0, 0x0, 0 },
};

signed char stepper_run_flag[3] = {0};

static void _cbHandlewinDialog(WM_MESSAGE * pMsg)
{
    WM_HWIN hItem;
    int NCode;
    int Id;

    switch (pMsg->MsgId)
    {
        case WM_INIT_DIALOG:
            //
            // Initialization of 'Framewin'
            //
            hItem = pMsg->hWin;
            FRAMEWIN_SetSkinClassic(hItem);
            FRAMEWIN_SetActive(hItem, 1);
            FRAMEWIN_SetTitleHeight(hItem, 32);
            FRAMEWIN_SetFont(hItem, GUI_FONT_20B_1);
            FRAMEWIN_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
            FRAMEWIN_SetText(hItem, "Handle");
            FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
            FRAMEWIN_SetClientColor(hItem, GUI_BLACK);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_0); //X+
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_1); //X-
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_2); //Y+
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_3); //Y-
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_5); //Z+
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_6); //Z-
            BUTTON_SetFont(hItem, GUI_FONT_32B_1);

			hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_0);
			TEXT_SetText(hItem, "Spindle speed");
			TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
			TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
			TEXT_SetFont(hItem, GUI_FONT_32B_1);
	
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0080FFFF));
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "00000");
            //
            // Initialization of 'position_text'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_2);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetText(hItem, "Position");
            TEXT_SetTextColor(hItem, GUI_WHITE);
            TEXT_SetFont(hItem, GUI_FONT_32B_ASCII);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_3);
            TEXT_SetText(hItem, "X:");
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_4);
            TEXT_SetFont(hItem, GUI_FONT_32B_ASCII);
            TEXT_SetText(hItem, "Y:");
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_5);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetText(hItem, "Z:");
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_6);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_7);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_8);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");
			
			
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_9);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "X:");
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_10);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetText(hItem, "Y:");
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_11);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "Z:");
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FFFF));
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
			
			
			
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_12);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_13);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JTEXT_14);
    TEXT_SetFont(hItem, GUI_FONT_D32);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    TEXT_SetText(hItem, "000.00");

            //
            // Initialization of 'x0'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_7);
            BUTTON_SetText(hItem, "x0");
            //
            // Initialization of 'x1'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_8);
            BUTTON_SetText(hItem, "x1");
            //
            // Initialization of 'x2'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_9);
            BUTTON_SetText(hItem, "x2");
            //
            // Initialization of 'x3'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_10);
            BUTTON_SetText(hItem, "x3");
            //
            // Initialization of 'x4'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_11);
            BUTTON_SetText(hItem, "x4");
            //
            // Initialization of 'x5'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_12);
            BUTTON_SetText(hItem, "x5");
            //
            // Initialization of 'x6'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_13);
            BUTTON_SetText(hItem, "x6");
            //
            // Initialization of 'x7'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_JBUTTON_14);
            BUTTON_SetText(hItem, "x7");
            break;

        case WM_NOTIFY_PARENT:
            Id    = WM_GetId(pMsg->hWinSrc);
            NCode = pMsg->Data.v;

            switch(Id)
            {
                case ID_JBUTTON_0: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
							stepper_run_flag[0] = 1;
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            stepper_run_flag[0] = 0;
                            break;
                    }

                    break;

                case ID_JBUTTON_1: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
							stepper_run_flag[0] = -1;
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            stepper_run_flag[0] = 0;
                            break;
                    }

                    break;

                case ID_JBUTTON_2: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
							stepper_run_flag[1] = 1;
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
							stepper_run_flag[1] = 0;
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_JBUTTON_3: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            stepper_run_flag[1] = -1;
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            stepper_run_flag[1] = 0;
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_JBUTTON_5: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_JBUTTON_6: // Notifications sent by 'Button'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)

                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;
				case ID_JBUTTON_7:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:	
//							beep_on();
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(0);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "00000");
							
							break;
					}
					break;
				case ID_JBUTTON_8:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(1);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "06000");
							
							break;
					}
					break;
				case ID_JBUTTON_9:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();				
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(2);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "10000");
							break;
					}
					break;
					
				case ID_JBUTTON_10:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(3);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "12000");
							break;
					}
					break;
				case ID_JBUTTON_11:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();
						break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(4);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "15000");
							break;
					}
					break;

				case ID_JBUTTON_12:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();		
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(5);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "18000");
							break;
					}
					break;
				case ID_JBUTTON_13:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();							
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(6);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "20000");
							break;
					}
					break;

				case ID_JBUTTON_14:
					switch(NCode)
					{
						case WM_NOTIFICATION_CLICKED:
//							beep_on();					
                            break;
						case WM_NOTIFICATION_RELEASED:
//							beep_off();
							motor_speed_con(7);
							TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_JTEXT_1), "24000");
							break;
					}
					break;
            }

            break;

        // USER START (Optionally insert additional message handling)
        // USER END
        default:
            WM_DefaultProc(pMsg);
            break;
    }
}


WM_HWIN CreateHandlewin(void);
WM_HWIN CreateHandlewin(void)
{
    WM_HWIN hWin;

    hWin = GUI_CreateDialogBox(_aDialogHandlewinCreate, GUI_COUNTOF(_aDialogHandlewinCreate), _cbHandlewinDialog, WM_HBKWIN, 0, 0);
    return hWin;
}

// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
